package com.lagou.edu.action;

import com.dubbo.demo.service.AnnotationService;
import com.dubbo.demo.service.SleepService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

@Component("annotationAction")
public class AnnotationAction {

    @DubboReference
    private AnnotationService annotationService;

    @DubboReference(filter = "TPMonitorFilter")
    private SleepService service;

    private static final Executor EXECUTOR = Executors.newCachedThreadPool();

    public String doSayHello(String name) {
        return annotationService.sayHello(name);
    }

    public void doSleepMethod() throws InterruptedException {

        for (int i = 0; i < 2000; i++) {
            EXECUTOR.execute(() -> service.methodA());
            EXECUTOR.execute(() -> service.methodB());
            EXECUTOR.execute(() -> service.methodC());

            TimeUnit.MILLISECONDS.sleep(15);
        }
    }

}